package view;

import java.awt.FlowLayout;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import controller.AboutListener;
import controller.menubar.ChangeLanguageListener;
import controller.menubar.QuitListener;
import controller.menubar.SystemInformationListener;
import controller.menubar.commands.PrintTable;
import controller.menubar.commands.SystemSerachListener;
import controller.menubar.commands.TerminalListener;
import controller.menubar.show.CheckSumVerify;
import controller.menubar.show.ShowSortByDate;
import controller.menubar.show.ShowSortByExtensions;
import controller.menubar.show.ShowSortBySize;

import model.GlobalParams;

public class MenuBar extends JMenuBar{		
	
	private static final long serialVersionUID = 1L;
	
	private JMenu FileMenu;
	private JMenu CommandsMenu;
	private JMenu ShowMenu;
	private JMenu ConfigurationMenu;
	
	//File
	private JMenuItem FileMenu_ChangeLanguage;
	private JMenuItem FileMenu_Print;
	private JMenuItem FileMenu_Properties;
	private JMenuItem FileMenu_EditComment;
	private JMenuItem FileMenu_CallculateOcupiedSpace;
	private JMenuItem FileMenu_Quit;
	private JMenuItem FileMenu_VerifyCheckSum;
	private JMenuItem FileMenu_CreateCheckSum;
	private JMenuItem FileMenu_ChangeAttributes;
	
	//Commands
	private JMenuItem CommandsMenu_Search;
	private JMenuItem CommandsMenu_SystemInformation;
	private JMenuItem CommandsMenu_OpenCommandPromtWindow;
	private JMenuItem CommandsMenu_BackgorundSystemManager;
	
	//Show
	private JMenuItem ShowMenu_Brief;
	private JMenuItem ShowMenu_Full;
	private JMenuItem ShowMenu_Comments;
	private JMenuItem ShowMenu_Tree;
	
	//Show Sorting
	private JMenuItem ShowMenu_Name;
	private JMenuItem ShowMenu_Extension;
	private JMenuItem ShowMenu_Time;
	private JMenuItem ShowMenu_Size;
	
	//Configuration
	private JMenuItem ConfigurationMenu_About;
	private JMenuItem ConfigurationMenu_ChangeSettingsFile;
	
	MainFrame frame;
	
	public MenuBar(MainFrame f) {	
		
		frame = f;
		
		setLayout(new WrapLayout(FlowLayout.LEFT));	
		
		configureMenuBar();
		configureFileMenu();
		configureCommandsMenu();
		configureShowMenu();
		configureConfigurationMenu();
		
		
		updateNames();

		add(FileMenu);
		add(CommandsMenu);
		add(ShowMenu);
		add(ConfigurationMenu);
		
		updateNames();
		
	}
	
	public void updateNames() {
		
		FileMenu.setText(GlobalParams.getInstance().stringCollection.getNameFileMenu());
		CommandsMenu.setText(GlobalParams.getInstance().stringCollection.getNameCommandsMenu());
		ShowMenu.setText(GlobalParams.getInstance().stringCollection.getNameShowMenu());
		ConfigurationMenu.setText(GlobalParams.getInstance().stringCollection.getNameConfigurationMenu());
		
		FileMenu_ChangeLanguage.setText(GlobalParams.getInstance().stringCollection.getFileMenu_ChangeLanguage()); 
		FileMenu_Print.setText(GlobalParams.getInstance().stringCollection.getFileMenu_Print()); 
		FileMenu_Properties.setText(GlobalParams.getInstance().stringCollection.getFileMenu_Properties()); 
		FileMenu_EditComment.setText(GlobalParams.getInstance().stringCollection.getFileMenu_EditComment()); 
		FileMenu_CallculateOcupiedSpace.setText(GlobalParams.getInstance().stringCollection.getFileMenu_CallculateOcupiedSpace());
		FileMenu_Quit.setText(GlobalParams.getInstance().stringCollection.getFileMenu_Quit()); 
		FileMenu_VerifyCheckSum.setText(GlobalParams.getInstance().stringCollection.getFileMenu_VerifyCheckSum()); 
		FileMenu_CreateCheckSum.setText(GlobalParams.getInstance().stringCollection.getFileMenu_CreateCheckSum()); 
		FileMenu_ChangeAttributes.setText(GlobalParams.getInstance().stringCollection.getFileMenu_ChangeAttributes()); 
		
		CommandsMenu_Search.setText(GlobalParams.getInstance().stringCollection.getCommandsMenu_Search()); 
		CommandsMenu_SystemInformation.setText(GlobalParams.getInstance().stringCollection.getCommandsMenu_SystemInformation()); 
		CommandsMenu_OpenCommandPromtWindow.setText(GlobalParams.getInstance().stringCollection.getCommandsMenu_OpenCommandPromtWindow()); 
		CommandsMenu_BackgorundSystemManager.setText(GlobalParams.getInstance().stringCollection.getCommandsMenu_BackgorundSystemManager()); 
		
		ShowMenu_Brief.setText(GlobalParams.getInstance().stringCollection.getShowMenu_Brief()); 
		ShowMenu_Full.setText(GlobalParams.getInstance().stringCollection.getShowMenu_Full()); 
		ShowMenu_Comments.setText(GlobalParams.getInstance().stringCollection.getShowMenu_Comments()); 
		ShowMenu_Tree.setText(GlobalParams.getInstance().stringCollection.getShowMenu_Tree()); 
		ShowMenu_Name.setText(GlobalParams.getInstance().stringCollection.getShowMenu_Name()); 
		ShowMenu_Extension.setText(GlobalParams.getInstance().stringCollection.getShowMenu_Extension()); 
		ShowMenu_Time.setText(GlobalParams.getInstance().stringCollection.getShowMenu_Time()); 
		ShowMenu_Size.setText(GlobalParams.getInstance().stringCollection.getShowMenu_Size()); 
		
		ConfigurationMenu_About.setText(GlobalParams.getInstance().stringCollection.getConfigurationMenu_Options());
		ConfigurationMenu_ChangeSettingsFile.setText(GlobalParams.getInstance().stringCollection.getConfigurationMenu_ChangeSettingsFile());
		
		
		
		
	}
	
	public void configureMenuBar() {
		FileMenu = new JMenu(GlobalParams.getInstance().stringCollection.getNameFileMenu());
		CommandsMenu = new JMenu(GlobalParams.getInstance().stringCollection.getNameCommandsMenu());
		ShowMenu = new JMenu(GlobalParams.getInstance().stringCollection.getNameShowMenu());
		ConfigurationMenu = new JMenu(GlobalParams.getInstance().stringCollection.getNameConfigurationMenu());
		
	}
	
	public void configureFileMenu() {
		FileMenu_ChangeLanguage = new JMenuItem();
		FileMenu_Print = new JMenuItem();
		FileMenu_Properties = new JMenuItem();
		FileMenu_EditComment = new JMenuItem();
		FileMenu_CallculateOcupiedSpace = new JMenuItem();
		FileMenu_Quit = new JMenuItem();
		FileMenu_VerifyCheckSum = new JMenuItem();
		FileMenu_CreateCheckSum = new JMenuItem();
		FileMenu_ChangeAttributes = new JMenuItem();
		
		
		FileMenu.add(FileMenu_Properties);
		FileMenu.add(FileMenu_ChangeLanguage);
		FileMenu.addSeparator();
		FileMenu.add(FileMenu_EditComment);
		FileMenu.add(FileMenu_ChangeAttributes);		
		FileMenu.add(FileMenu_Print);		
		FileMenu.add(FileMenu_CallculateOcupiedSpace);
		FileMenu.addSeparator();
		FileMenu.add(FileMenu_VerifyCheckSum);
		FileMenu.add(FileMenu_CreateCheckSum);
		FileMenu.addSeparator();
		FileMenu.add(FileMenu_Quit);		
		
		
		FileMenu_Print.addActionListener(new PrintTable(frame));
		FileMenu_ChangeLanguage.addActionListener(new ChangeLanguageListener(frame));
		FileMenu_Quit.addActionListener(new QuitListener(frame));
		FileMenu_VerifyCheckSum.addActionListener(new CheckSumVerify(frame));
		
	}
	public void configureCommandsMenu() {
		
		CommandsMenu_Search = new JMenuItem();
		CommandsMenu_SystemInformation = new JMenuItem();
		CommandsMenu_OpenCommandPromtWindow = new JMenuItem();
		CommandsMenu_BackgorundSystemManager = new JMenuItem();
		
		CommandsMenu.add(CommandsMenu_Search);
		CommandsMenu.add(CommandsMenu_SystemInformation);
		CommandsMenu.add(CommandsMenu_OpenCommandPromtWindow);
		CommandsMenu.add(CommandsMenu_BackgorundSystemManager);	
		
		CommandsMenu_OpenCommandPromtWindow.addActionListener(new TerminalListener());
		CommandsMenu_SystemInformation.addActionListener(new SystemInformationListener(frame));
		CommandsMenu_Search.addActionListener(new SystemSerachListener(frame));
	}
	public void configureShowMenu() {	
		
		ShowMenu_Brief = new JMenuItem();
		ShowMenu_Full = new JMenuItem();
		ShowMenu_Comments = new JMenuItem();
		ShowMenu_Tree = new JMenuItem();
		ShowMenu_Name = new JMenuItem();
		ShowMenu_Extension = new JMenuItem();
		ShowMenu_Time = new JMenuItem();
		ShowMenu_Size = new JMenuItem();
		
		//ShowMenu.add(ShowMenu_Brief);
		//ShowMenu.add(ShowMenu_Full);
		//ShowMenu.add(ShowMenu_Comments);
		//ShowMenu.add(ShowMenu_Tree);
		//ShowMenu.addSeparator();
		ShowMenu.add(ShowMenu_Name);
		ShowMenu.add(ShowMenu_Extension);
		ShowMenu.add(ShowMenu_Time);
		ShowMenu.add(ShowMenu_Size);
		
		ShowMenu_Name.addActionListener(new ShowSortByDate(frame));
		ShowMenu_Extension.addActionListener(new ShowSortByExtensions(frame));
		ShowMenu_Time.addActionListener(new ShowSortByDate(frame));
		ShowMenu_Size.addActionListener(new ShowSortBySize(frame));
		
	}
	public void configureConfigurationMenu() {
		
		ConfigurationMenu_About = new JMenuItem();
		ConfigurationMenu_ChangeSettingsFile = new JMenuItem();		
		
		ConfigurationMenu_About.addActionListener(new AboutListener(frame));
		
		ConfigurationMenu.add(ConfigurationMenu_About);
		ConfigurationMenu.add(ConfigurationMenu_ChangeSettingsFile);
	}
	
	
		
	
	

}
